<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>


<html>
<head>
	<title>竞赛账号管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});


		function paw(){
			var a = document.getElementById("password1").value;
			var b =	document.getElementById("password2").value;
			if(a == b){
				document.getElementById("pw").innerHTML = "*";
				document.getElementById("btnSubmit").disabled=false;
			}else{
				document.getElementById("pw").innerHTML = "*输入与上面相同的密码";
				document.getElementById("btnSubmit").disabled=true;
			}
		}


		function lonigN1(){
			document.getElementById("inline").innerHTML = "*";
			document.getElementById("inline").style.color="red";
		}

		function lonigN(haha){
			var  id = document.getElementById("LN").value;
			console.info();
			$.ajax({
				type: "POST",
				url: "${ctx}/race/raceUser/lists",
				data: {
				},
				success: function (Class) {
					var a = 0;
					for(var i = 0; i < Class.length; i++){
						if(Class[i].loginName == id){
							a++;
						}
					}
					if(a != 0 ){

						document.getElementById("inline").innerHTML = "登录名已存在 *";
						document.getElementById("inline").style.color="red";
						document.getElementById("LN").focus();
					}
				},
				error:function(){
					console.info("error");
				}
			});
		}



		function btn(id,passwords){

          var password = document.getElementById("Password").value;

			if(id != null && id != ""){

				if(password == null || password == ""){
					document.getElementById("Password").value=",.,";
					document.getElementById("confirmNewPassword").value=",.,";
				}
			}
		}

//		function myCheck(){
//			var  team1 = document.getElementById("teamId").value;
//			if(team1 == ""){
//				alert(123)
//				return false;
//			}else{
//				alert(33)
//			return true;
//			}
//		}


	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/race/raceUser/">竞赛账号列表</a></li>
		<li class="active"><a href="${ctx}/race/raceUser/form?id=${raceUser.id}">  <shiro:hasPermission name="race:raceUser:edit">${not empty raceUser.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="race:raceUser:edit">查看</shiro:lacksPermission>账号</a></li>
	</ul><br/>
	<form:form onSubmit="" id="inputForm" modelAttribute="raceUser" action="${ctx}/race/raceUser/save" method="post" class="form-horizontal" >
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">登录名：</label>
			<div class="controls">
				<form:input path="loginName" htmlEscape="false" maxlength="100" class="input-xlarge required" onblur="lonigN(${raceUser.id})" onclick="lonigN1()" id="LN"/>
				<span class="help-inline" id="inline"><font color="red">*</font> </span>
			</div>
		</div>



		<%--<div class="control-group">--%>
			<%--<label class="control-label">密码：</label>--%>
			<%--<div class="controls">--%>
				<%--<form:input type="password" path="password"  htmlEscape="false" maxlength="100"  class="input-xlarge required" id="password1"/>--%>
				<%--<span class="help-inline"><font color="red">*</font> </span>--%>
			<%--</div>--%>
		<%--</div>--%>



		<%--<div class="control-group">--%>
		  <%--<label class="control-label">确定密码：</label>--%>
	    	<%--<div class="controls">--%>
			<%--<input onblur="paw()" type="password"  maxlength="100"  style="width: 270px" id="password2"/>--%>
			<%--<span class="help-inline"><font color="red" id="pw">*</font> </span>--%>
		   <%--</div>--%>
	   <%--</div>--%>






	<div class="control-group">
		<label class="control-label">密码：</label>
		<div class="controls">
			<input id="Password" name="Password"  type="password" value="" maxlength="50" minlength="3"
				   class="${empty raceUser.id?'required':''}"/>
			<c:if test="${empty raceUser.id}"><span class="help-inline"><font color="red">*</font> </span></c:if>
			<c:if test="${not empty raceUser.id}"><span class="help-inline">若不修改密码，请留空。</span></c:if>
		</div>
	</div>

	<div class="control-group">
		<label class="control-label">确认密码:</label>
		<div class="controls">
			<input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="50"
				   minlength="3" equalTo="#Password"/>
			<c:if test="${empty raceUser.id}"><span class="help-inline"><font color="red">*</font> </span></c:if>
		</div>
	</div>


		<div class="control-group">
			<label class="control-label">姓名：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="100" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">所属团队：</label>
			<div class="controls">
				<form:select id="teamId" path="teamId" class="input-xlarge required" >
					<c:forEach items="${raceTeams}" var="raceTeam">
						<form:option value="${raceTeam.teamName}" label="${raceTeam.teamName}"/>
						<form:options items="${fns:getDictList('')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</c:forEach>
				</form:select>

				<c:if test="${raceTeams == '[]'}">
					<span class="help-inline"><font color="red">请先添加团队</font> </span>
				</c:if>
				<c:if test="${raceTeams != '[]'}">
				<span class="help-inline"><font color="red">*</font> </span>
				</c:if>
			</div>
		</div>



		<div class="control-group">
			<label class="control-label">手机：</label>
			<div class="controls">
				<form:input path="mobile" htmlEscape="false" maxlength="11" minlength="11" class="input-xlarg" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();"/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">邮箱：</label>
			<div class="controls">
				<form:input path="email" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">组织：</label>
			<div class="controls">
				<form:input path="organization" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>




		<div class="form-actions">
			<shiro:hasPermission name="race:raceUser:edit"><input onclick="btn('${raceUser.id}','${raceUser.password}')" id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>